<template>
  <div class="UserRegister_container">
    <div class="UserRegister_box">
      <div class="UserRegister-title">注册账号</div>

      <el-form
        ref="loginForm"
        :model="user"
        status-icon
        class="UserRegister-form"
      >
        <el-form-item prop="username">
          <el-input v-model="user.username" placeholder="请输入账号"></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="user.password"
            show-password
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="user.againpassword"
            show-password
            placeholder="请再次输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item prop="email">
          <el-input v-model="user.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
        <el-form-item class="btn">
          <el-button type="primary" icon @click="doRegister()"
            >注册账号</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserLogin",
  data() {
    return {
      user: {
        username: "",
        email: "",
        password: "",
      },
    };
  },
  created() {
    // console.log($);
    // console.log("1111");
  },
  methods: {
    doRegister() {
      if (!this.user.username) {
        this.$message.error("请输入用户名！");
        return;
      } else if (!this.user.email) {
        this.$message.error("请输入邮箱！");
        return;
      } else if (this.user.email != null) {
        var reg =
          /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        if (!reg.test(this.user.email)) {
          this.$message.error("请输入有效的邮箱！");
        } else if (!this.user.password) {
          this.$message.error("请输入密码！");
          return;
        } else if (this.user.againpassword !== this.user.password) {
          this.$message.error("两次密码不相同！");
        } else {
          
            this.$message({
              message: "注册成功",
               showClose: true,
              type: "success",
            }),
          this.$router.push(
            { path: "/" }

          );
        }
      }
    },
  },
};
</script>
<style lang="less" scoped>
.UserRegister_container {
  height: 100%;
  width: 100%;
  background: url(../assets/sushe.jpg) no-repeat fixed center;

  min-height: 100vh;
  background-size: cover;

  &__header {
    padding-top: 60px;
    text-align: center;
    font-size: 32px;
    color: #fff;
  }

  &__page {
    width: 440px;
    margin: 0 auto;
    margin-top: 60px;
  }
}
.UserRegister_box {
  width: 450px;
  height: 350px;
  border-radius: 5px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(255, 255, 255, 0);
  box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.7);
  border-radius: 10px;
}
.UserRegister-form {
  position: absolute;
  bottom: 0;
  width: 90%;
  top: 50px;
  right: 20px;
  box-sizing: border-box;
}

.btn {
  display: flex;
  justify-content: flex-end;
}
.el-button {
  background-color: rgb(75, 62, 62);
}

.el-button:hover{
  background-color: rgba(255, 255, 255, 0);

}
.UserRegister-title {
  position: absolute;
  left: 40%;
  top: 5%;

  font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  font-style: Arial;
  font-size: 20px;
  font-weight: bold;
  color:#fff;
}
.UserRegister {
  margin: 20px;
}
.div {
  height: 60px;
  width: 90px;
  background-color: pink;
  position: absolute;
  left: 10px;
  margin: 20px;
  font-size: 1rem;
}
// .el-form-item__label{
//   position: absolute;
//   top:20px;
//   color:pink;
// }
</style>